import time
from Tools import Tools
from selenium import webdriver
from selenium.webdriver.common.by import By
import unittest
import logging

class A3mall(unittest.TestCase):

    def setUp(self) -> None:
        Tools().Log1()
        self.driver=webdriver.Firefox()
        self.driver.maximize_window()
        self.driver.get('http://10.59.9.12:7001/')
        time.sleep(3)

    def tearDown(self) -> None:
        time.sleep(3)
        self.driver.quit()

    def test_A3mall_01_login(self):
        logging.info('start.case')
        self.driver.find_element(By.XPATH, '/html/body/div[1]/div/div[2]/ul/li[1]/a').click()
        time.sleep(3)
        # 断言1：断言文本：会员登陆
        dy1 = self.driver.find_element(By.CLASS_NAME, 'reg-new').text
        print("文本断言3，会员登陆:", dy1)
        time.sleep(2)
        # 用户名  密码
        self.driver.find_element(By.NAME,'username').send_keys('13811033962')
        time.sleep(3)
        self.driver.find_element(By.NAME, 'password').send_keys("123456")
        time.sleep(8)
        # 登录按钮
        self.driver.find_element(By.XPATH, '//*[@id="theForm"]/div[5]/a').click()
        time.sleep(5)
        # 断言2：断言文本：欢迎回来，13811033962
        dy2 = self.driver.find_element(By.XPATH, '/html/body/div[1]/div/div[2]/ul/li[1]/a').text
        print("文本断言2，欢迎回来，13811033962:", dy2)
        time.sleep(2)
        # 断言3：断言文本：账户余额：¥ 988389770.25  中的 988389770.25
        dy3 = self.driver.find_element(By.XPATH, '/html/body/div[5]/div[2]/div[1]/div[2]/div[2]/ul/li[4]').text
        dy31 = dy3.replace('¥ ', '')
        print("文本断言3，账户余额:", dy31)
        time.sleep(2)

    def test_ms_01(self):
        # 调用成功登录用例
        self.test_A3mall_01_login()
        time.sleep(5)
        #点击秒杀进入秒杀列表
        self.driver.find_element(By.XPATH,'/html/body/div[3]/div[2]/ul/li[4]/a').click()
        time.sleep(3)
        #点击商品进入详情页面
        self.driver.find_element(By.XPATH,'/html/body/div[5]/div[2]/div[2]/div[1]/ul/li[5]/div[1]/span/a/img').click()
        time.sleep(3)
        #断言 商品详情：茅台two
        dy4=self.driver.find_element(By.XPATH,'/html/body/div[4]/a[3]').text
        print("断言：",dy4)
        #点击立即购买
        self.driver.find_element(By.ID,'buy-cart').click()
        time.sleep(3)
        #断言5 立即购买：确认订单信息
        dy5=self.driver.find_element(By.XPATH,'/html/body/div[4]/div[2]/ul/li[2]/em').text
        print("断言：", dy5)
        #选择地址
        self.driver.find_element(By.ID,'address-801').click()
        time.sleep(3)
        #支付订单
        self.driver.find_element(By.ID,'order-button').click()
        time.sleep(3)
        #断言 支付：您的订单支付成功
        dy6=self.driver.find_element(By.XPATH,'/html/body/div[4]/div[3]/span').text
        print("断言：",dy6)
        logging.info('case.end')